package com.nowcoder.code.hjnc;

import java.util.Scanner;

public class HJ02 {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        Integer i4 = scanner.nextInt();
        System.out.println(count4(i4, String.valueOf(i4).length()));
    }

    public static int count4(int i4, int n) {
        int[] i4s = new int[n];
        int[] i4sum = new int[n];
        int lastSum = 0;
        int last4Sum = 0;
        int pow10 = 1;
        for (int i = 0; i < n; i++) {
            i4s[i] = pow10 + 8 * lastSum;
            i4sum[i] = last4Sum + i4s[i];
            last4Sum = i4sum[i];
            pow10 = pow10 * 10;
            lastSum = lastSum + i4s[i];
        }

        int tmp4 = i4;

        int result = tmp4 % 10 >= 4 ? 1 : 0;
        tmp4 = tmp4 / 10;
        int i = 0;
        int pow = 10;

        while (tmp4 != 0) {
            int y = tmp4 % 10;
            int s10;
            if (y >= 4) {
                s10 = pow;
                y--;
            } else {
                s10 = 0;
            }
            int r = y * i4sum[i] + s10;
            result = result + r;

            pow = pow * 10;
            i++;
            tmp4 = tmp4 / 10;
        }

        return i4 - result;

    }

}
